odoo.define('tree_button.button_action', function (require) {
    "use strict";

    var View = require('web.View');
    var Model = require('web.Model');
    var ListView = require('web.ListView');

    ListView.include({
        render_buttons: function ($node) {
            this._super.apply(this, arguments);
            if (this.$buttons) {
                // 通过属性名绑定动作
                this.$buttons.find('.oe_list_button_news').click(this.proxy('new_action_1'));
            }
        },

        // 可以直接调用模型方法
        new_action_1: function () {
            var self = this
            var tree_button = new Model("tree.button");
            tree_button.call("func").then(function (result) {
                console.log(result);
            });
        },

        // 也可以调出模型视图,比如打开一个向导视图,action参数于python中一致
        new_action_2:function () {
            var self = this;
            this.do_action({
                name: "列表视图",
                res_model: "tree.button",
                // 注意tree视图类型在js中使用'list'
                // views: [[false, 'list'], [false, 'form']],
                views: [[false, 'form']],
                type: 'ir.actions.act_window',
                target: "new",
                context: self.dataset.get_context(),
                flags: {
                    action_buttons: false,
                }
            });
        },
    })

    View.include({
        // 判断按钮是否显示
        is_action_enabled: function (action) {
            // 这里'add_new'与add_button.xml中widget.is_action_enabled('add_new')对应
            if (action == "add_new") {
                var attrs = this.fields_view.arch.attrs;
                return (action in attrs) ? JSON.parse(attrs[action]) : false;
            } else {
                return this._super.apply(this, arguments);
            }

        }
    })

})